package cn.iocoder.yudao.module.handguard.dal.mysql.applicationdeductrecord;

import java.math.BigDecimal;
import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.handguard.dal.dataobject.applicationdeductrecord.ApplicationDeductRecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.handguard.controller.app.applicationdeductrecord.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 产品订单-提成明细记录 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ApplicationDeductRecordMapper extends BaseMapperX<ApplicationDeductRecordDO> {

    default PageResult<ApplicationDeductRecordDO> selectPage(ApplicationDeductRecordPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ApplicationDeductRecordDO>()
                .eqIfPresent(ApplicationDeductRecordDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(ApplicationDeductRecordDO::getProductAccessId, reqVO.getProductAccessId())
                .eqIfPresent(ApplicationDeductRecordDO::getProductAccessRecordId, reqVO.getProductAccessRecordId())
                .eqIfPresent(ApplicationDeductRecordDO::getDeductType, reqVO.getDeductType())
                .eqIfPresent(ApplicationDeductRecordDO::getDirectProfit, reqVO.getDirectProfit())
                .eqIfPresent(ApplicationDeductRecordDO::getIndirectProfit, reqVO.getIndirectProfit())
                .eqIfPresent(ApplicationDeductRecordDO::getGrossProfit, reqVO.getGrossProfit())
                .eqIfPresent(ApplicationDeductRecordDO::getRegionalManagerRoyalty, reqVO.getRegionalManagerRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getBusinessSupervisorRoyalty, reqVO.getBusinessSupervisorRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getBusinessManagerRoyalty, reqVO.getBusinessManagerRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getReferrerRoyalty, reqVO.getReferrerRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getClientRoyalty, reqVO.getClientRoyalty())
                .betweenIfPresent(ApplicationDeductRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ApplicationDeductRecordDO::getId));
    }

    default List<ApplicationDeductRecordDO> selectList(ApplicationDeductRecordExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ApplicationDeductRecordDO>()
                .eqIfPresent(ApplicationDeductRecordDO::getOrderId, reqVO.getOrderId())
                .eqIfPresent(ApplicationDeductRecordDO::getProductAccessId, reqVO.getProductAccessId())
                .eqIfPresent(ApplicationDeductRecordDO::getProductAccessRecordId, reqVO.getProductAccessRecordId())
                .eqIfPresent(ApplicationDeductRecordDO::getDeductType, reqVO.getDeductType())
                .eqIfPresent(ApplicationDeductRecordDO::getDirectProfit, reqVO.getDirectProfit())
                .eqIfPresent(ApplicationDeductRecordDO::getIndirectProfit, reqVO.getIndirectProfit())
                .eqIfPresent(ApplicationDeductRecordDO::getGrossProfit, reqVO.getGrossProfit())
                .eqIfPresent(ApplicationDeductRecordDO::getRegionalManagerRoyalty, reqVO.getRegionalManagerRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getBusinessSupervisorRoyalty, reqVO.getBusinessSupervisorRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getBusinessManagerRoyalty, reqVO.getBusinessManagerRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getReferrerRoyalty, reqVO.getReferrerRoyalty())
                .eqIfPresent(ApplicationDeductRecordDO::getClientRoyalty, reqVO.getClientRoyalty())
                .betweenIfPresent(ApplicationDeductRecordDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ApplicationDeductRecordDO::getId));
    }

    BigDecimal getPlatformProfit(@Param("staType") Integer staType);
}
